import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:hitutor/UI/Home/Home.dart';
import 'package:hitutor/UI/NoticeAndMessage/ItemNotice.dart';
import 'package:hitutor/Util/Global.dart';
import 'package:hitutor/Util/HttpGo.dart';
import 'package:hitutor/Widget/MyDialog.dart';
import 'package:hitutor/Widget/MyPage.dart';

import 'DialogReadNotice.dart';

class NoticeList extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _NoticeList();
  }
}

class _NoticeList extends State<NoticeList> {
  List<dynamic> noticeList = [];

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
      HttpGo(context).get("/Information/GetAnnouncementList?studentId=${Global.studentId}", {}, (data) {
        noticeList = data["announcementList"];
        setState(() {});
      }, (code, error) => showToast(error));
    });
  }

  @override
  Widget build(BuildContext context) {
    return MyPage(
        "公告",
        Container(
            child: ListView.builder(
                itemCount: noticeList.length,
                itemBuilder: (BuildContext context, int index) {
                  return ItemNotice(noticeList[index], onTap: () {
                    showWidgetDialog(
                        context,
                        DialogReadNotice(noticeList[index], readCallback: () {
                          noticeList[index]["confirmDateTime"] = "1";
                          setState(() {});
                        }));
                  });
                })));
  }
}
